-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NEW-FEATURE: Announcement messages #200
Conversation
Pull Request Test Coverage Report for Build 5795969658Details
💛 - Coveralls |
@kimakan did you add some docs about this feature in docs repo? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with it. Do we have /want an example placeholder for the default app?
The documentation will be added after the merge. |
add condition possibility on visibility of message, based on preprogrammed filters. Usecase: show user with |
I came up with a possible solution for this that allows adding new conditions/filters easily. The filters/conditions are defined in class MessageFilter:
CHOICES = (
("no_filter", "Show to all users"),
("user_has_not_consented", "Show to user who has not consented yet"),
)
def no_filter(request):
return True
def user_has_not_consented(request):
if request.user.is_authenticated:
if not request.user.profile.consent:
return True
return False New conditions can be added directy as methods of the class The ...
visibility_filter = models.CharField(max_length=30, choices=MessageFilter.CHOICES, default="no_filter")
def get_filter(self):
return getattr(MessageFilter, str(self.visibility_filter))
... The actual filtering of the messages happens in the templatetags @register.inclusion_tag("contact/announcements.html", takes_context=True)
def show_announcements(context):
request = context["request"]
announcements = AnnouncementMessage.objects.filter(visible=True)
announcements = [msg for msg in announcements if msg.get_filter()(request) is True]
return {
"announcements": announcements,
} This solution requires |
I think that is exactly what we need, the |
Hi @kimakan @agy-why sorry for interupt, running |
@jochenklar that is a good feed back, thanks! I think we will not add the filtering app wise but globally on daiquiri, but it worth discussing. |
If you want choices to be flexible you can implement them like |
@jochenklar , Thank you for the feedback! I have implemented the announcement messages following your suggestion. Now, the new conditions do not require a migration. The default A new filter can be added as following (i.e. in the from daiquiri.contact.filters import DefaultMessageFilter
class MyAppMessageFilter(DefaultMessageFilter):
CHOICES = DefaultMessageFilter.CHOICES + (
("custom_condition", "Show to the custom group of users"),
)
def custom_condition(request):
return True And then set the new message filter in the settings with ANNOUNCEMENT_MESSAGE_FILTER = 'daiquiri.myapp.filters.MyAppMessageFilter' The current CI tests are failing because the settings from the |
This feature make it possible to announce maintenance and downtime.
The announcements are defined in
contact/model.py
. They can be added and updated via the Django admin interface. In order to make the announcements visible on the webpage, the announcement tags must be loaded and used in the templates.For example:
In place of
{% show_announcements %}
, the messages will be shown as bootstrap alerts sorted byupdated
time with the most currently updated message on top.The announcement types are
info
,warning
,urgent
which corresponds to the bootstrap alert typesalert-info
,alert-warning
andalert-danger
. We may add other types, but I don't think it's necessary since these three types are more than enough for most use cases.Needed improvements
Currently, the template for the rendered announcement message is barebone and might require some custom styling. It might be even useful to make some of the styling adjustable via scss variables, similar to daiquiri/core/static/core/css/variables.scss. However even in the current state, the template
contact/announcements.html
can be overloaded by the app anytime and use a custom styling in it.